package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * OrderController
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/8/5 9:32
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderService orderService;

    /**
     * 条件搜索
     *
     * @param ordersPageQueryDTO 订单查询页面dto
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 统计数据
     *
     * @return {@link Result}<{@link OrderStatisticsVO}>
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 详情
     *
     * @param id id
     * @return {@link Result}<{@link OrderVO}>
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> detailsById(@PathVariable Long id) {
        OrderVO orderVO = orderService.detailsById(id);
        return Result.success(orderVO);
    }

    /**
     * 确认
     *
     * @param ordersConfirmDTO 订单确认dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/confirm")
    public Result<?> confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒绝
     *
     * @param ordersRejectionDTO 订单被拒绝dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/rejection")
    public Result<?> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 取消
     *
     * @param ordersCancelDTO 订单取消dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/cancel")
    public Result<?> cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 交付通过id
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/delivery/{id}")
    public Result<?> deliveryById(@PathVariable Long id) {
        orderService.deliveryById(id);
        return Result.success();
    }

    /**
     * 完成订单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/complete/{id}")
    public Result<?> completeById(@PathVariable Long id) {
        orderService.completeById(id);
        return Result.success();
    }

}
